home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Borland Plateform / Turbo Pascal V7.0 / DOCDEMO.ZIP / SUPPLIER.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-10-30  |  5.8 KB  |  219 lines

  1. {************************************************}
  2. {                                                }
  3. {   Turbo Vision 2.0 Demo                        }
  4. {   Copyright (c) 1992 by Borland International  }
  5. {                                                }
  6. {************************************************}
  7.  
  8. unit Supplier;
  9.  
  10. interface
  11.  
  12. uses TutConst, Drivers, Objects, TutTypes, Dialogs, Count;
  13.  
  14. type
  15.   PSupplierDialog = ^TSupplierDialog;
  16.   TSupplierDialog = object(TDialog)
  17.     SupplierNum, Company, Addr1, Addr2, Addr3, Phone: PInputLine;
  18.     Counter: PCountView;
  19.     constructor Init;
  20.     procedure CancelSupplier;
  21.     procedure EnterNewSupplier;
  22.     procedure HandleEvent(var Event: TEvent); virtual;
  23.     procedure SaveSupplierData;
  24.     procedure ShowSupplier(ASupplierNum: Integer);
  25.     function Valid(Command: Word): Boolean; virtual;
  26.   end;
  27.  
  28. var
  29.   SupplierColl: PCollection;
  30.   SupplierInfo: PSupplier;
  31.   TempSupplier: PSupplierObj;
  32.  
  33. procedure LoadSuppliers;
  34. procedure SaveSuppliers;
  35.  
  36.  
  37. implementation
  38.  
  39. uses Views, Validate;
  40.  
  41. const
  42.   CurrentSupplier: Integer = 0;
  43.  
  44. constructor TSupplierDialog.Init;
  45. var
  46.   R: TRect;
  47. begin
  48.   R.Assign(0, 0, 60, 15);
  49.   inherited Init(R, 'Suppliers');
  50.   Options := Options or ofCentered;
  51.   HelpCtx := $D000;
  52.  
  53.   R.Assign(15, 2, 23, 3);
  54.   SupplierNum := New(PInputLine, Init(R, 6));
  55.   SupplierNum^.SetValidator(New(PPXPictureValidator, Init('&&####', True)));
  56.   Insert(SupplierNum);
  57.   R.Assign(2, 2, 15, 3);
  58.   Insert(New(PLabel, Init(R, 'Supplier #:', SupplierNum)));
  59.  
  60.   R.Assign(12, 4, 57, 5);
  61.   Company := New(PInputLine, Init(R, 45));
  62.   Insert(Company);
  63.   R.Assign(2, 4, 12, 5);
  64.   Insert(New(PLabel, Init(R, 'Company:', Company)));
  65.  
  66.   R.Assign(12, 6, 57, 7);
  67.   Addr1 := New(PInputLine, Init(R, 60));
  68.   Insert(Addr1);
  69.   R.Assign(2, 6, 12, 7);
  70.   Insert(New(PLabel, Init(R, 'Address:', Addr1)));
  71.  
  72.   R.Assign(12, 7, 57, 8);
  73.   Addr2 := New(PInputLine, Init(R, 60));
  74.   Insert(Addr2);
  75.  
  76.   R.Assign(12, 8, 57, 9);
  77.   Addr3 := New(PInputLine, Init(R, 60));
  78.   Insert(Addr3);
  79.  
  80.   R.Assign(12, 10, 34, 11);
  81.   Phone := New(PInputLine, Init(R, 20));
  82.   Phone^.SetValidator(New(PPXPictureValidator, Init('[(###) ]###-####', False)));
  83.   Insert(Phone);
  84.   R.Assign(2, 10, 12, 11);
  85.   Insert(New(PLabel, Init(R, 'Phone:', Phone)));
  86.  
  87.   R.Assign(2, 12, 12, 14);
  88.   Insert(New(PButton, Init(R, '~N~ew', cmSupplierNew, bfNormal)));
  89.   R.Assign(13, 12, 23, 14);
  90.   Insert(New(PButton, Init(R, '~S~ave', cmSupplierSave, bfDefault)));
  91.   R.Assign(24, 12, 34, 14);
  92.   Insert(New(PButton, Init(R, 'Re~v~ert', cmSupplierCancel, bfNormal)));
  93.   R.Assign(35, 12, 45, 14);
  94.   Insert(New(PButton, Init(R, 'Next', cmSupplierNext, bfNormal)));
  95.   R.Assign(46, 12, 56, 14);
  96.   Insert(New(PButton, Init(R, 'Prev', cmSupplierPrev, bfNormal)));
  97.  
  98.   R.Assign(5, 14, 20, 15);
  99.   Counter := New(PCountView, Init(R));
  100.   with Counter^ do
  101.   begin
  102.     SetCount(SupplierColl^.Count);
  103.     SetCurrent(CurrentSupplier + 1);
  104.   end;
  105.   Insert(Counter);
  106.  
  107.   DisableCommands([cmSupplierPrev]);
  108.  
  109.   SelectNext(False);
  110. end;
  111.  
  112. procedure TSupplierDialog.CancelSupplier;
  113. begin
  114.   if CurrentSupplier = SupplierColl^.Count then
  115.   begin
  116.     Dispose(TempSupplier, Done);
  117.     ShowSupplier(CurrentSupplier - 1)
  118.   end
  119.   else ShowSupplier(CurrentSupplier);
  120. end;
  121.  
  122. procedure TSupplierDialog.EnterNewSupplier;
  123. begin
  124.   CurrentSupplier := SupplierColl^.Count;
  125.   TempSupplier := New(PSupplierObj, Init);
  126.   SupplierInfo := @(TempSupplier^.TransferRecord);
  127.   SetData(SupplierInfo^);
  128.   Counter^.SetCurrent(CurrentSupplier + 1);
  129.   DisableCommands([cmSupplierNew, cmSupplierNext, cmSupplierPrev]);
  130.   EnableCommands([cmSupplierCancel, cmSupplierSave]);
  131. end;
  132.  
  133. procedure TSupplierDialog.HandleEvent(var Event: TEvent);
  134. begin
  135.   inherited HandleEvent(Event);
  136.   if Event.What = evCommand then
  137.     case Event.Command of
  138.       cmSupplierNext:
  139.         begin
  140.           ShowSupplier(CurrentSupplier + 1);
  141.           ClearEvent(Event);
  142.         end;
  143.       cmSupplierPrev:
  144.         begin
  145.           ShowSupplier(CurrentSupplier - 1);
  146.           ClearEvent(Event);
  147.         end;
  148.       cmSupplierNew:
  149.         begin
  150.           EnterNewSupplier;
  151.           ClearEvent(Event);
  152.         end;
  153.       cmSupplierCancel:
  154.         begin
  155.           CancelSupplier;
  156.           ClearEvent(Event);
  157.         end;
  158.       cmSupplierSave:
  159.         begin
  160.           SaveSupplierData;
  161.           ClearEvent(Event);
  162.         end;
  163.     end;
  164. end;
  165.  
  166. procedure TSupplierDialog.SaveSupplierData;
  167. begin
  168.   if Valid(cmClose) then
  169.   begin
  170.     if CurrentSupplier = SupplierColl^.Count then
  171.       SupplierColl^.Insert(TempSupplier);
  172.     GetData(SupplierInfo^);
  173.     SaveSuppliers;
  174.   end;
  175.   EnableCommands([cmSupplierPrev, cmSupplierNew]);
  176. end;
  177.  
  178. procedure TSupplierDialog.ShowSupplier(ASupplierNum: Integer);
  179. begin
  180.   CurrentSupplier := ASupplierNum;
  181.   SupplierInfo := @PSupplierObj(SupplierColl^.At(CurrentSupplier))^.TransferRecord;
  182.   SetData(SupplierInfo^);
  183.   Counter^.SetCurrent(CurrentSupplier + 1);
  184.   if CurrentSupplier > 0 then EnableCommands([cmSupplierPrev])
  185.   else DisableCommands([cmSupplierPrev]);
  186.   if SupplierColl^.Count > 0 then
  187.     EnableCommands([cmSupplierNext]);
  188.   if CurrentSupplier >= SupplierColl^.Count - 1 then
  189.     DisableCommands([cmSupplierNext]);
  190. end;
  191.  
  192. function TSupplierDialog.Valid(Command: Word): Boolean;
  193. begin
  194.   if Command = cmSupplierCancel then
  195.     Valid := True
  196.   else Valid := inherited Valid(Command);
  197. end;
  198.  
  199. procedure LoadSuppliers;
  200. var
  201.   SupplierFile: TBufStream;
  202. begin
  203.   SupplierFile.Init('SUPPLIER.DAT', stOpenRead, 1024);
  204.   SupplierColl := PCollection(SupplierFile.Get);
  205.   SupplierFile.Done;
  206.   SupplierInfo := @(PSupplierObj(SupplierColl^.At(0))^.TransferRecord);
  207. end;
  208.  
  209. procedure SaveSuppliers;
  210. var
  211.   SupplierFile: TBufStream;
  212. begin
  213.   SupplierFile.Init('SUPPLIER.DAT', stOpenWrite, 1024);
  214.   SupplierFile.Put(SupplierColl);
  215.   SupplierFile.Done;
  216. end;
  217.  
  218. end.
  219.